package cn.com.jit.time.manage.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.hibernate.impl.SessionFactoryImpl;

import cn.com.jit.time.manage.models.User;

public class UserDao {

	private SessionFactoryImpl sessionFactory;
	
	public User findone(String username){
		Session session = sessionFactory.openSession();
		Transaction tx = session.beginTransaction();
		String hql = "from User  where username='" + username + "'";
		List<User> users = new ArrayList<User>();
		users = (List<User>)session.createQuery(hql).list();
		//User users = (User) session.get(User.class, hql);
		tx.commit();
		if(users.size()==0){
			return null;
		}else{
			User user = users.get((users.size()-1));
			return user;
		}
		
		
		
	}

	public SessionFactoryImpl getSessionFactory() {
		return sessionFactory;
	}

	public void setSessionFactory(SessionFactoryImpl sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	
}
